# import requests
# from lxml import etree
# from log.header import get_headers
#
#
# url = 'https://snake.timeline.ink/latest'
# res = requests.get(url,headers=get_headers())
# print(res.text)
#
#
# import hashlib, base64, requests
# from Crypto.Cipher import AES
#
# # ----------- 底层 AES -----------
# def _md5(s: str) -> str:
#     return hashlib.md5(s.encode()).hexdigest()
#
# def _aes_cbc_zero_decrypt(hex_str: str, key_str: str) -> str:
#     key = (key_str * 16)[-16:]                      # 16 字节 key
#     iv  = _md5(key)[8:24]                            # 16 字节 iv
#     cipher = bytes.fromhex(hex_str)                  # hex → bytes
#     aes = AES.new(key.encode(), AES.MODE_CBC, iv.encode())
#     plain = aes.decrypt(cipher).rstrip(b'\x00')      # 去 ZeroPadding
#     try:
#         return plain.decode('utf-8')
#     except Exception:
#         return hex_str
#
# # ----------- URL 解密 -----------
# def decrypt_url(enc_url: str, provider: int = 0) -> str:
#     if not enc_url:
#         return ""
#     key_str = 'wesurely' if provider == 4 else 'huaban'
#
#     head, _, query = enc_url.partition('?')
#     parts = head.split('/')
#     fname, dot, ext = parts[-1].partition('.')
#     if len(fname) < 32:               # 不是加密格式
#         return enc_url
#     pre, post = fname[:32], fname[32:]
#     pre_dec = _aes_cbc_zero_decrypt(pre, key_str)
#     if not pre_dec:                   # 解密失败
#         return enc_url
#     parts[-1] = f"{pre_dec}{post}{dot}{ext}"
#     return '/'.join(parts) + ('?' + query if query else '')
#
# # ----------- 演示 -----------
# if __name__ == '__main__':
#     u = "https://gd-hbimg.huaban.com/95eae6c489170bbc2c0886be8ad98dffce630063aeff24113ee788519d292-xANYDo"
#     real = decrypt_url(u, provider=0)
#     print(real)                       # 解密后 URL
#     # 顺手验证 200
#     print(requests.head(real, timeout=5).status_code)

import requests
headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Pragma': 'no-cache',
    'Sec-Fetch-Dest': 'document',
    'Sec-Fetch-Mode': 'navigate',
    'Sec-Fetch-Site': 'none',
    'Sec-Fetch-User': '?1',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
    'sec-ch-ua': '"Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

response = requests.get(
    'https://p.ananas.chaoxing.com/star3/400_0cQ80/f3bd86a079aee501e79ecafa9c61140f.webp',
    headers=headers,
)
with open ('demo.png','wb') as f:
    f.write(response.content)